package com.ruoyi.controller.jpjs.capital;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.jpjs.capital.CapitalInputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 劳资数据录入
 * @date 2021/4/10 10:08
 */

@Controller
@RequestMapping("/capitalInput")
public class capitalInputController extends BaseController {

    @Autowired
    CapitalInputService capitalInputService;

    private String prefix = "jpjs/capital/input";

    @GetMapping()
    public String capitalInput(ModelMap mmap) {
        return prefix + "/capitalinput";
    }

    @RequestMapping("/selectAllPro")
    @ResponseBody
    public TableDataInfo selectAllPro(@RequestParam Map map) {
        startPage();
        List<Map<String, Object>> list = capitalInputService.selectAllPro(map);
        return getDataTable(list);
    }

    @RequestMapping("/selectDataDate")
    @ResponseBody
    public TableDataInfo selectDataDate(String proId) {
        return getDataTable(capitalInputService.selectDataDate(proId));
    }

    @RequestMapping("/selectData")
    @ResponseBody
    public TableDataInfo selectData(String project_id, String years, String months, String days) {
        List<Map<String, Object>> list = capitalInputService.selectData(project_id, years, months, days);
        return getDataTable(list);
    }

    @RequestMapping("/selectPositionByProjectId")
    @ResponseBody
    public List<Map<String, Object>> selectPositionByProjectId(String projectId) {
        List<Map<String, Object>> list = capitalInputService.selectPositionByProjectId(projectId);
        return list;
    }

    @RequestMapping("/updateData")
    @ResponseBody
    public int updateData(String years, String months, String days, String work_id, String position, String value) {
        return capitalInputService.updateCapitalData(years, months, days, work_id, position, value);
    }

    @GetMapping("/add")
    public String add(String id, ModelMap mmap) {
        Map capitalData = capitalInputService.selectCapitalDataById(id);
        mmap.put("capitalData", capitalData);
        return prefix + "/add";
    }

    @RequestMapping("/proDataAdd")
    @ResponseBody
    public AjaxResult proDataAdd(@RequestParam Map map) {
        return toAjax(capitalInputService.proDataAdd(map));
    }

    @RequestMapping("deleteData")
    @ResponseBody
    public AjaxResult deleteData(@RequestParam Map map) {
        return toAjax(capitalInputService.deleteData(map));
    }
}
